package client.comm.baoding.ui

import android.view.View
import client.comm.baoding.BaseMiddleActivity
import client.comm.baoding.R
import client.comm.baoding.adapter.RankingAdapter
import client.comm.baoding.adapter.SubsidyAdapter
import client.comm.baoding.api.bean.LevelIncome
import client.comm.baoding.api.bean.RankingList
import client.comm.baoding.databinding.ActivityFxRankBinding
import client.comm.baoding.databinding.ActivitySubsidyDataBinding
import client.comm.baoding.ui.vm.SubsideDataViewModel
import client.comm.commlib.comm_ui.draw.SpaceItemBottomDecoration
import client.comm.commlib.widget.EmptyLayout

/**
 * Date: 2022/11/24 10:37
 * Description: 分销排行榜
 */
class FxRankListActivity : BaseMiddleActivity<SubsideDataViewModel, ActivityFxRankBinding>() {

    override fun getLayout(): Int {
        return R.layout.activity_fx_rank
    }

    override fun initViewModel(): SubsideDataViewModel = createViewModel()

    val adapter: RankingAdapter by lazy {
        RankingAdapter(this, mImgLoader)
    }

    override fun initView() {
        super.initView()
        binding.event = this
        binding.recyclerView.adapter = adapter
        binding.recyclerView.addItemDecoration(SpaceItemBottomDecoration(1))
        binding.refreshLayout.setOnRefreshListener {
            viewModel.getRankList()
        }
        viewModel.isOneLoading.observe(this, {
            if (!it) {
                binding.refreshLayout.isRefreshing = false
            }
        })
        viewModel.callRank.observe(this, {
            it?.let {
                if (it.isSuccess) {
                    val list = it.data?.ranking_list as MutableList<RankingList.Ranking?>
                    adapter.submitList(list)
//                        adapter.hasMoreState.value = false
                }
            }
        })
    }


    override fun initData() {
        super.initData()
        viewModel.getRankList()
        adapter.hasMoreState.value = false
    }


}